{include file="public/head"}
<div class="main">
    {include file="public/left"}
    <div class="middle">
    {include file="public/header"}
    <div class="login_tab">
        <ul class="log_in">
            <dl class="log_title"><i class="fa fa-address-card" aria-hidden="true"></i><span>{:__('用户登陆')}</span></dl>
            <dl class="log_option">
                <dd class="log_img">
                    <div class="log_image">
                        <i class="layui-icon">&#xe612;</i>
                    </div>
                </dd>
                <dd class="log_sub">
                    <div class="log_tip">{:__('如果您在本站已拥有帐号，请使用已有的帐号信息直接进行登录即可，不需重复注册。')}</div>
                    <div class="log_acc">
                        <label nowrap="nowrap">{:__('用户名')}：</label>
                        <input id="account" autocomplete="off" class="layui-input" type="text"/>
                    </div>
                    <div class="log_pwd">
                        <label nowrap="nowrap">{:__('密码')}：</label>
                        <input id="pwd" autocomplete="off" class="layui-input" type="password"/>
                    </div>
                    <!-- layui-form-checked -->
                    <div id="login_status" class="log_status layui-unselect layui-form-checkbox" lay-skin="primary">
                        <span>{:__('记住登录状态')}</span><i class="layui-icon"></i>
                    </div>
                    <div class="log_btn">
                        <button type="button" id="log_in" class="layui-btn layui-btn-lg layui-btn-normal">{:__('登陆')}</button>
                        <a  href="/index/Index/fogetpwd">{:__('忘记密码')}？</a>
                    </div>
                </dd>
            </dl>
            <!-- <dl>
                <hr></hr>
                <b>其他账户登陆</b>
            </dl> -->
        </ul>
        <ul class="no_log">
            <p class="no_log_tip">{:__('还没有其他账号吗')}?</p>
            <span class='regist_tip'>{:__('还没有其他账号吗?为更好的使用我们的服务,请首先注册一个账号')}</span>
            <dl class="regist_btn">
                <a href="/index/Index/regist" class="layui-btn layui-btn-lg layui-btn-warm">{:__('马上注册')}</a>
            </dl>
            <dl class="no_log_service">
                <p class="serve_intro">{:__('注册后您可以享受以下服务')}</p>
                <div class="no_log_get">
                    <p class="get_img money">{:__('赏')}</p>
                    <p class='get_info'>
                        <span>{:__('我要悬赏')}</span>
                        <span>{:__('更低的成本，更多的选择')}</span>
                    </p>
                </div>
                <div class="no_log_get">
                    <p class="get_img getmoney">$</p>
                    <p class='get_info'>
                        <span>{:__('我要赚钱')}</span>
                        <span>{:__('能力变现，有本事你就来')}</span>
                    </p>
                </div>
            </dl>
            <!-- <dl class="not_log_info">
                <p class="no_log_question">帐号尚未激活?</p>
                <span class="no_log_answer"><a href="">点击这里</a>重新发送确认邮件。</span>
                <p class="no_log_question">没有确认邮件？</p>
                <span class="no_log_answer">可能您的邮箱地址不正确，点击此处<a href="">我要重置</a>邮箱</span>
            </dl> -->
        </ul>
    </div>
    {include file="public/foot"}
    </div>
    {include file="public/right"}
</div>
{include file="public/footer"}
<script>
    
    $(function(){
        account = $.cookie('account');
        pwd = $.cookie('pwd');
        $("#account").val(account);
        $("#pwd").val(pwd);
        if($.cookie("think_lang") == 'en-us'){
            $(".money").css("font-size","17px");
        }
        if($.cookie("think_lang") == 'zh-cn'){
            $(".log_acc label, .log_pwd label").css("width","18%");
        }
        if($.cookie('account')!='' && $.cookie('account') != null && $.cookie('account') != undefined){
            $("#login_status").trigger("click");
        }
    });
    $(".log_status").click(function(){
        var _this = $(this);
        if(_this.hasClass('layui-form-checked')){
            _this.removeClass('layui-form-checked');
        } else{
            _this.addClass('layui-form-checked');
        }
    });

    $("#log_in").click(function(){
        var account = $("#account").val();
        var pwd = $("#pwd").val();
        if(account == '' || pwd ==''){
            layer.msg("{:__('用户名或者密码不能为空')}",{icon:2});
            return false;
        }
        var login_status = 0;
        if($(".log_status").hasClass("layui-form-checked")){
            login_status = 1;
        }

        $.ajax({
            url:'/api/user/verifyExist',
            type:"post",
            data:{username:account},
            success:function(ret){
                if(ret['data'] != '' && ret['data'] != undefined && ret['data'] != null){
                    if(ret['data']['exists'] == 0){
                        layer.msg("{:__('用户不存在')}",{icon:2});
                        return false;
                    } else {

                        $.ajax({
                            url:'/api/user/login',
                            type:'post',
                            data:{'account':account,'password':pwd},
                            success:function(ret){                              
                                var flag = 0;
                                if(ret.code != 401 && ret.code != 1){
                                    $.cookie('account','');
                                    $.cookie('pwd','');
                                    layer.msg(ret.msg,{icon:2});
                                } else if(ret.code == 1){
                                    if(login_status == 1){
                                        $.cookie('account',account,{expires:7200});
                                        $.cookie('pwd',pwd,{expires:7200});
                                    } else {
                                        $.cookie('account','');
                                        $.cookie('pwd','');
                                    }
                                    if(ret.data['token'] != ''){
                                        token = ret.data['token'];
                                        var objs = {'token':token};
                                        $(document).queue("outcache",function(){
                                            var userData = getLocalStorage('userData');
                                            var userdata = JSON.parse(userData);
                                            if(userdata == '' || userdata == null || userdata == undefined || userdata['profile'] == '' || userdata['profile'] == null || userdata['profile'] == undefined || userdata['profile']['truename'] == '' || userdata['profile']['truename'] == undefined || userdata['profile']['truename'] == ''){
                                                window.location.href="/index/User/updateinfo";
                                            } else {
                                                window.location.href="/";
                                            }
                                        });
                                        CacheLoad(objs);
                                    } else {
                                        layer.msg("{:__('api错误')}",{icon:2});
                                        return false;
                                    }
                                    
                                }
                            }
                        });
                    }
                }
                
            }
        });
    });
</script>
